#include "Util.hpp"
#include "Config.hpp"
#include "DataManage.hpp"
#include "HotManage.hpp"
#include "Service.hpp"
#include <thread>
cloud::DataManager *data;
void TestUtil(std::string filename)
{
    // cloud::FileUtil util(filename);
    // std::cout << util.FileName() << std::endl;
    // std::cout << util.FileSize() << std::endl;
    // std::cout << util.LastATime() << std::endl;
    // std::cout << util.LastMTime() << std::endl;

    // cloud::FileUtil fu1(filename);
    // std::string body;
    // fu1.GetContent(&body);

    // cloud::FileUtil fu2("./hello.txt");
    // fu2.SetContent(body);

    // const std::string packname = filename + ".lz";
    // cloud::FileUtil fu(filename);
    // fu.Compress(packname);

    // cloud::FileUtil nfu(packname);
    // fu.UnCompress("./hello.txt");
    cloud::FileUtil fu(filename);
    fu.CreateDirectory();
    std::vector<std::string> array;
    fu.ScanDirectory(&array);
    for (auto &ch : array)
    {
        std::cout << ch << std::endl;
    }
}
void TestJsonUtil()
{
    const char *name = "小明";
    int age = 18;
    float socre[] = {78, 84.5, 92.5};
    Json::Value root;
    root["姓名"] = name;
    root["年龄"] = age;
    root["成绩"].append(socre[0]);
    root["成绩"].append(socre[1]);
    root["成绩"].append(socre[2]);
    std::string json_str;
    cloud::JsonUtil::Serialize(root, &json_str);
    std::cout << json_str << std::endl;

    Json::Value value;
    cloud::JsonUtil::UnSerialize(json_str, &value);
    std::cout << value["姓名"].asString() << std::endl;
    std::cout << value["年龄"].asString() << std::endl;
    for (int i = 0; i < value["成绩"].size(); i++)
    {
        std::cout << value["成绩"][i].asFloat() << std::endl;
    }
}
void TestConfig()
{

    std::cout << cloud::Config::GetInstance()->GetHotTime() << std::endl;
    std::cout << cloud::Config::GetInstance()->GetServerPort() << std::endl;
    std::cout << cloud::Config::GetInstance()->GetServerIp() << std::endl;
    std::cout << cloud::Config::GetInstance()->GetDownloadPrefix() << std::endl;
    std::cout << cloud::Config::GetInstance()->GetPackfileSuffix() << std::endl;
    std::cout << cloud::Config::GetInstance()->GetBackDir() << std::endl;
    std::cout << cloud::Config::GetInstance()->GetPackDir() << std::endl;
    std::cout << cloud::Config::GetInstance()->GetBackupFile() << std::endl;
}
void TestData(std::string filename)
{
    // cloud::BackupInfo info;
    // info.NewBackupInfo(filename, &info);
    // std::cout << info.pack_flag << std::endl;
    // std::cout << info.fsize << std::endl;
    // std::cout << info.atime << std::endl;
    // std::cout << info.mtime << std::endl;
    // std::cout << info.real_path << std::endl;
    // std::cout << info.pack_path << std::endl;
    // std::cout << info.url_path << std::endl;
    // cloud::BackupInfo info;
    // info.NewBackupInfo(filename, &info);
    // cloud::DataManger data;
    // data.Insert(info);

    // cloud::BackupInfo tmp;
    // data.GetOneByURL(info.url_path, &tmp);
    // std::cout << tmp.pack_flag << std::endl;
    // std::cout << tmp.fsize << std::endl;
    // std::cout << tmp.atime << std::endl;
    // std::cout << tmp.mtime << std::endl;
    // std::cout << tmp.real_path << std::endl;
    // std::cout << tmp.pack_path << std::endl;
    // std::cout << tmp.url_path << std::endl;
    // std::cout << "----------GetAll----------------" << std::endl;
    // tmp.pack_flag = true;
    // data.Update(tmp);
    // std::vector<cloud::BackupInfo> array;
    // data.GetAll(&array);
    // for (auto &a : array)
    // {
    //     std::cout << a.pack_flag << std::endl;
    //     std::cout << a.fsize << std::endl;
    //     std::cout << a.atime << std::endl;
    //     std::cout << a.mtime << std::endl;
    //     std::cout << a.real_path << std::endl;
    //     std::cout << a.pack_path << std::endl;
    //     std::cout << a.url_path << std::endl;
    // }

    cloud::DataManager data;
    std::vector<cloud::BackupInfo> array;
    data.GetAll(&array);
    for (auto &a : array)
    {
        std::cout << a.pack_flag << std::endl;
        std::cout << a.fsize << std::endl;
        std::cout << a.atime << std::endl;
        std::cout << a.mtime << std::endl;
        std::cout << a.real_path << std::endl;
        std::cout << a.pack_path << std::endl;
        std::cout << a.url_path << std::endl;
    }
}

void TestHot()
{
    cloud::HotManager hot;
    hot.RunModule();
}

void TestService()
{
    
    cloud::Service service;
    service.RunModule();
}
int main(int argc, char *argv[])
{
    data = new cloud::DataManager();
    // TestUtil(argv[1]);
    // TestJsonUtil();
    //  TestConfig();
    // TestData(argv[1]);
    // TestHot();
    std::thread thread_hot_mamager(TestService);
    std::thread thread_data_mamager(TestHot);

    thread_data_mamager.join();
    thread_hot_mamager.join();
    return 0;
}